/*
 * @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @Date: 2024-06-20 09:51:29
 * @LastEditors: 别拿暗恋当饭吃. 13466071+lililkli@user.noreply.gitee.com
 * @LastEditTime: 2024-06-23 20:59:00
 * @FilePath: \sx_demo2\sx_demo2\config\webpack.config.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const EslintWebpackPlugin = require("eslint-webpack-plugin");

module.exports = {
  mode: "development",
  entry: path.resolve(__dirname, "../src", "index.tsx"),
  output: {
    path: path.resolve(__dirname, "../dist"),
    filename: "[name].bundle.js",
    assetModuleFilename: "assets/[name][hash][ext][query]",
    publicPath: "/",
    clean: true,
  },

  module: {
    rules: [
      {
        test: /\.(png|jpg|jpeg|gif|svg)$/,
        type: "asset",
        parser: {
          dataUrlCondition: {
            maxSize: 8 * 1024,
          },
        },
      },
      {
        test: /\.css$/,
        // exclude: /node_modules/,
        use: ["style-loader", "css-loader"],
      },
      {
        test: /\.scss$/,
        exclude: /node_modules/,
        use: ["style-loader", "css-loader", "sass-loader"],
      },
      {
        test: /\.(ts|tsx)$/,
        exclude: /node_modules/,
        use: [
          "cache-loader",
          {
            loader: "ts-loader",
            options: {
              transpileOnly: true,
            },
          },
        ],
      },
      {
        enforce: "pre",
        test: /\.js$/,
        exclude: /node_modules/,
        use: ["eslint-loader"],
      },
    ],
  },

  plugins: [
    new HtmlWebpackPlugin({
      inject: "body",
      minify: true,
      //   templateContent: '<div id="root"></div>',
      template: path.resolve(__dirname, "../public", "index.html"),
    }),
    new EslintWebpackPlugin({
      context: path.resolve(__dirname, "../src"),
      extensions: [".js", ".jsx", ".ts", ".tsx"],
    }),
  ],

  resolve: {
    alias: {
      "@": path.resolve(__dirname, "../src"),
      components: path.resolve(__dirname, "../src", "components"),
      pages: path.resolve(__dirname, "../src", "pages"),
      hooks: path.resolve(__dirname, "../src", "hooks"),
      utils: path.resolve(__dirname, "../src", "utils"),
      assets: path.resolve(__dirname, "../src", "assets"),
      routes: path.resolve(__dirname, "../src", "routes"),
      store: path.resolve(__dirname, "../src", "store"),
      services: path.resolve(__dirname, "../src", "services"),
    },
    extensions: [".js", ".jsx", ".ts", ".tsx"],
  },
};
